# -*- coding: utf-8 -*-
import datetime

from django.db import models


# Create your models here.
class Activity(models.Model):
    username=models.CharField(max_length=30)
    province=models.CharField(max_length=10)
    city=models.CharField(max_length=30)
    activityname=models.CharField(max_length=100)
    description=models.TextField(blank=True,null=True)
    address=models.CharField(max_length=50,blank=True)
    date=models.DateField()   
    member=models.TextField(blank=True,null=True)
    is_open=models.CharField(max_length=5,default=0)
    datetime=models.DateTimeField()
    
    def __unicode__(self):
        return self.username
    
    class Meta:
        ordering=['username']
    class Admin:
        pass   


class JoinActivityManager(models.Manager):
    def create_joinActivity(self,username,activityId):
        '''
        save activity that user joined
        '''
        now=datetime.datetime.now()
        ja=self.model(username=username,activityId=activityId,datetime=now)
        ja.save(using=self._db)
        return ja


class JoinActivity(models.Model):
    username=models.CharField(max_length=50)
    activityId=models.CharField(max_length=20)
    datetime=models.DateTimeField()
    objects=models.Manager()
    ja_objects=JoinActivityManager()
    
    def __unicode__(self):
        return self.username
    
    class Meta:
        ordering=['datetime']
    
    class Admin:
        pass
    
class Suggestion(models.Model):
    activity=models.ForeignKey(Activity)
    author_id=models.CharField(max_length=20)
    suggestion_author=models.CharField(max_length=50)
    suggestContext=models.TextField(blank=True,null=True)
    datetime=models.DateTimeField()
    
    def __unicode__(self):
        return self.suggestion_author
    
    class Meta:
        ordering=['datetime']
    
    class Admin:
        pass
